<#assign contextPath=springMacroRequestContext.getContextPath()/>
<#import "/public/frame/main.html" as frame/>
<@frame.head "南航明珠商城-<#if isUpdate>修改<#else>发布</#if>活动"></@frame.head>
<div class="page-container">
  <form autocomplete="off" method="post" name="save_form" id="save_form" action="${contextPath}/presentActivityController/<#if isUpdate>update_activity<#else>save_activity</#if>">    
	<input type="hidden" name="id" id="activeId" value="${active.id}"/>
	<div class="text-c">
      <table class="table">
        <tr>
          <td style="width: 15%">活动类型：</td>
          <td style="width: 30%">
            <span class="select-box radius">
              <select class="select" id="activityType" name="activeType" onchange="activeTypeChange();" <#if isUpdate>disabled="disabled"</#if>>
                <option value="4" <#if 4==active.activeType>selected="selected"</#if>>买赠活动</option>
                <option value="5" <#if 5==active.activeType>selected="selected"</#if>>满赠活动</option>
              </select>
            </span>
          </td>
          <td style="width: 55%"><font color="red">*</font>&nbsp;请选择活动类型</td>
        </tr>
        <tr>
          <td>活动名称：</td>
          <td><input id="name" name="name" class="input-text radius"  placeholder="请输入活动名称" value="${active.name}"/></td>
          <td><font color="red">*</font>&nbsp;请输入200字以内的活动名称</td>
        </tr>
        <tr>
          <td>开始时间：</td>
          <td>
            <input id="startDate" name="startDate" value='${(active.startDate?string("yyyy-MM-dd HH:mm:ss"))!}' class="input-text radius Wdate"
            onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'endDate\')}',readOnly: true})"/>
           </td>
          <td><font color="red">*</font>&nbsp;请选择开始时间</td>
        </tr>
        <tr>
          <td>结束时间：</td>
          <td>
            <input id="endDate" name="endDate" value='${(active.endDate?string("yyyy-MM-dd HH:mm:ss"))!}' class="input-text radius Wdate"
            onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'startDate\')}',readOnly: true})"/>
          </td>
          <td><font color="red">*</font>&nbsp;请选择结束时间</td>
        </tr>
        <tr>
          <td>是否与买赠活动同享：</td>
          <td>
            <div class="radio-box">
              <input type="radio" id="isShareBuyActive1" name="isShareBuyActive" value="1" <#if !isUpdate>checked="checked"<#else><#if active.isShareBuyActive=="1">checked="checked"</#if></#if>/>
              <label for="isShareBuyActive1" style="cursor: pointer;">同享</label>
            </div>
            <div class="radio-box">
              <input type="radio" id="isShareBuyActive2" name="isShareBuyActive" value="0" <#if active.isShareBuyActive=="0">checked="checked"</#if>/>
              <label for="isShareBuyActive2" style="cursor: pointer;">不同享</label>
            </div>
          </td>
          <td><font color="red">*</font>&nbsp;请选择是否与买赠活动同享</td>
        </tr>
        <tr>
          <td>是否与满赠活动同享：</td>
          <td>
            <div class="radio-box">
              <input type="radio" id="isShareFullActive1" name="isShareFullActive" value="1" <#if !isUpdate>checked="checked"<#else><#if active.isShareFullActive=="1">checked="checked"</#if></#if>/>
              <label for="isShareFullActive1" style="cursor: pointer;">同享</label>
            </div>
            <div class="radio-box">
              <input type="radio" id="isShareFullActive2" name="isShareFullActive" value="0" <#if active.isShareFullActive=="0">checked="checked"</#if>/>
              <label for="isShareFullActive2" style="cursor: pointer;">不同享</label>
            </div>
          </td>
          <td><font color="red">*</font>&nbsp;请选择是否与满赠活动同享</td>
        </tr>
        <tr class="manzeng"> <!-- 满赠时显示 -->
          <td>活动商品范围：</td>
          <td>
            <div class="radio-box">
              <input type="radio" id="fullActiveScope1" name="fullActiveScope" value="1" <#if !isUpdate>checked="checked"<#else><#if active.fullActiveScope=="1">checked="checked"</#if></#if>/>
              <label for="fullActiveScope1" style="cursor: pointer;">全部商品</label>
            </div>
            <div class="radio-box">
              <input type="radio" id="fullActiveScope2" name="fullActiveScope" value="2" <#if active.fullActiveScope=="2">checked="checked"</#if>/>
              <label for="fullActiveScope2" style="cursor: pointer;">指定商品</label>
            </div>
          </td>
          <td><font color="red">*</font>&nbsp;请选择活动商品</td>
        </tr>
        <tr class="maizeng">
          <td>活动商品：</td>
          <td>
            <button type="button" class="btn btn-primary radius size-S" onclick="toAddProduct();">点击选择商品</button>
            &nbsp;您已选择&nbsp;<strong id="buyProNum" style="font-size: 14px;">0</strong>&nbsp;款商品
          </td>
          <td></td>
        </tr>
        <tr class="maizeng">
          <td></td>
          <td colspan="2">
            <div class="text-c">
              <table id="buyProTb" class="table table-border table-bordered table-bg radius table-hover">
                <thead> 
                  <tr>
                    <th style="width: 10%">商品编号</th>
                    <th style="width: 20%">商品名称</th>
                    <th style="width: 10%">商品价格</th>
                    <th style="width: 10%">购买数量</th>
                    <th style="width: 10%">赠品编号</th> 
	  			    <th style="width: 20%">赠品名称</th>
                    <th style="width: 10%">赠品数量</th>
                    <th style="width: 10%">操作</th>
                  </tr>
                </thead>
                <tbody id="buyProTbody">
                  <#if isUpdate && buyProList??>
                	<#list buyProList as burPro>
                	  <tr id="${'buyProTr_' + (burPro_index + 1)}">
                	    <td id="${'buyProTd_id_' + (burPro_index + 1)}">${burPro.product.id}</td>
                	    <td id="${'buyProTd_name_' + (burPro_index + 1)}">${burPro.product.baseInfo.name}</td>
                	    <td id="${'buyProTd_payOneMileage_' + (burPro_index + 1)}">${burPro.product.priceInfo.payOneMileage}公里</td>
                	    <td id="${'buyProTd_saleNum_' + (burPro_index + 1)}" style="padding: 4px;"><input id="${'buyPro_saleNum_' + (burPro_index + 1)}" value="${burPro.buyNum}" class="input-text radius size-S" style="text-align:center;ime-mode:Disabled" onkeyup="value=value.replace(/[^\d]/g,'')" ondrop="return false;" maxlength="12"/></td>
                	    <td id="${'buyProTd_preId_' + (burPro_index + 1)}">${burPro.present.id}</td>
                	    <td id="${'buyProTd_preName_' + (burPro_index + 1)}">${burPro.present.name}</td>
                	    <td id="${'buyProTd_preNum_' + (burPro_index + 1)}" style="padding: 4px;"><input id="${'buyPro_preNum_' + (burPro_index + 1)}" value="${burPro.presentNum}" class="input-text radius size-S" style="text-align:center;ime-mode:Disabled" onkeyup="value=value.replace(/[^\d]/g,'')" ondrop="return false;" maxlength="12"/></td>
                	    <td>
                	      <a href="javascript:;" class="btn-link" onclick="buy_toAddPresent('${'buyProTr_' + (burPro_index + 1)}');">赠品</a>&nbsp;&nbsp;
                	      <a href="javascript:;" class="btn-link" style="color: red;" onclick="deleteDomById('${'buyProTr_' + (burPro_index + 1)}');">删除</a>
                	    </td>
                	  </tr>
                	</#list>
                  </#if>
                </tbody>
              </table>
            </div>
          </td>
        </tr>
        <tr class="manzeng">
          <td colspan="3">
        	<table class="table" style="border: 1px solid #DCDCDC;padding: 0px; margin: 0px;" cellpadding="0" cellspacing="0">
        	  <tr style="padding: 0px; margin: 0px;">
				<td id="ruleTd" style="padding: 0px; margin: 0px;">
				  <#if isUpdate>
				    <#list fullPresentRule as rule>
				      <table id="ruleTb_${rule_index + 1}" name="ruleTb" class="table" style="padding: 0px; margin: 0px;" cellpadding="0" cellspacing="0">
				  	    <tr>
				  	      <td colspan="3" style="font-weight: bold;font-size: 15px;padding: 5px 0px 0px 5px;">
				  	                     规则${rule_index + 1}：
				  	        <#if rule_index gt 0>
				  	          <input type="button" class="btn btn-danger radius size-S" onclick="deleteDomById('ruleTb_${rule_index + 1}');" value="删除规则"/>
				  	        </#if>
				  	      </td>
				        </tr>
				  	    <tr>
				  	      <td style="width: 14%;">订单金额：</td>
				  	      <td style="width: 30%;"><input id="orderPrice_${rule_index + 1}" value="${rule.orderMoney}" class="input-text radius size-S" style="ime-mode:disabled" onkeyup="value=value.replace(/[^\d]/g,'')" ondrop="return false;" maxlength="12"/></td>
				  	      <td style="width: 56%;"><font color="red">*</font>&nbsp;请输入订单金额（公里）</td>
				  	    </tr>
				  	    <tr>
				  	      <td>活动赠品：</td>
				  	      <td>
				  	        <input type="button" class="btn btn-primary radius size-S" onclick="full_toAddPresent('rulePresentTbody_${rule_index + 1}');" value="添加赠品"/>
				  	        &nbsp;您已选择&nbsp;<strong id="rulePreNum_${rule_index + 1}" style="font-size: 14px;">0</strong>&nbsp;款赠品
				  	      </td>
				  	      <td></td>
				  	    </tr>
				  	    <tr>
				  	      <td></td>
				  	      <td colspan="2">
				      	    <div class="text-c">
				        	  <table id="rulePresentTb_${rule_index + 1}" class="table table-border table-bordered table-bg radius table-hover">
				          	    <thead> 
				            	  <tr>
				                    <th style="width: 20%;">赠品编号</th> 
				   	  			    <th style="width: 25%;">赠品名称</th>
				   	  			    <th style="width: 25%;">供应商</th>
				              	    <th style="width: 10%;">剩余库存</th>
				              	    <th style="width: 10%;">赠品数量</th>
				              	    <th style="width: 10%;">操作</th>
								  </tr>
				          	    </thead>
				          	    <tbody id="rulePresentTbody_${rule_index + 1}">
				          	      <#list rule.rulePresentList as rulePre>
				          	        <tr id="rulePresentTr_${rule_index + 1}_${rulePre.present.id}">
				          	          <td id="rulePresentTd_id_${rule_index + 1}_${rulePre.present.id}">${rulePre.present.id}</td>
				          	          <td>${rulePre.present.name}</td>
				          	          <td>${rulePre.present.merchant.mercName}</td>
				          	          <td>${rulePre.present.presentStock - rulePre.present.presentSaleStock}</td>
				          	          <td style="padding: 4px;"><input class="input-text radius size-S" value="${rulePre.presentSum}" id="rulePresent_preNum_${rule_index + 1}_${rulePre.present.id}" style="text-align:center;ime-mode:Disabled" onkeyup="value=value.replace(/[^\d]/g,'')" ondrop="return false;" maxlength="12"/></td>
				          	          <td><a href="javascript:;" style="color: red;" onclick="deleteDomById('rulePresentTr_${rule_index + 1}_${rulePre.present.id}');">删除</a></td>
				          	        </tr>
				          	      </#list>
				          	    </tbody>
				        	  </table>
				      	    </div>
				  	      </td>
				  	    </tr>
			          </table>
				    </#list>
				  <#else>
				    <table id="ruleTb_1" name="ruleTb" class="table" style="padding: 0px; margin: 0px;" cellpadding="0" cellspacing="0">
				  	  <tr><td colspan="3" style="font-weight: bold;font-size: 15px;padding: 5px 0px 0px 5px;">规则1：</td></tr>
				  	  <tr>
				  	    <td style="width: 14%;">订单金额：</td>
				  	    <td style="width: 30%;"><input id="orderPrice_1" class="input-text radius size-S" style="ime-mode:disabled" onkeyup="value=value.replace(/[^\d]/g,'')" ondrop="return false;" maxlength="12"/></td>
				  	    <td style="width: 56%;"><font color="red">*</font>&nbsp;请输入订单金额（公里）</td>
				  	  </tr>
				  	  <tr>
				  	    <td>活动赠品：</td>
				  	    <td>
				  	      <input type="button" class="btn btn-primary radius size-S" onclick="full_toAddPresent('rulePresentTbody_1');" value="添加赠品"/>
				  	      &nbsp;您已选择&nbsp;<strong id="rulePreNum_1" style="font-size: 14px;">0</strong>&nbsp;款赠品
				  	    </td>
				  	    <td></td>
				  	  </tr>
				  	  <tr>
				  	    <td></td>
				  	    <td colspan="2">
				    	  <div class="text-c">
				      	    <table id="rulePresentTb_1" class="table table-border table-bordered table-bg radius table-hover">
				        	  <thead> 
				          	    <tr>
				                  <th style="width: 20%;">赠品编号</th> 
				   				  <th style="width: 25%;">赠品名称</th>
				   				  <th style="width: 25%;">供应商</th>
				            	  <th style="width: 10%;">剩余库存</th>
				            	  <th style="width: 10%;">赠品数量</th>
				            	  <th style="width: 10%;">操作</th>
				          	    </tr>
				        	  </thead>
				        	  <tbody id="rulePresentTbody_1"></tbody>
				      	    </table>
				    	  </div>
				  	    </td>
				  	  </tr>
			        </table>
			      </#if>
		        </td>
			  </tr>
			  <tr style="padding: 0px; margin: 0px;"> 
        		<td style="padding: 0px; margin: 0px;"> 
        		  <table class="table" style="padding: 0px; margin: 0px;" cellpadding="0" cellspacing="0">
        			<tr>
        			  <td style="width:14%;"></td>
        			  <td style="width:30%;"><input type="button" class="btn btn-success radius size-S" onclick="addRule();" value="新增规则"/></td>
        			  <td style="width:56%;"></td>
        			</tr>
        		  </table>
        		</td>
			  </tr>
        	</table>
          </td>
        </tr>
        <tr class="manzeng-zhiding"> <!-- 满赠-选择指定商品时显示 -->
          <td>活动商品：</td>
          <td>
            <button type="button" class="btn btn-primary radius size-S" onclick="toAddProduct();">点击选择商品</button>
            &nbsp;您已选择&nbsp;<strong id="fullProNum" style="font-size: 14px;">0</strong>&nbsp;款商品
          </td>
          <td></td>
        </tr>
        <tr class="manzeng-zhiding">
          <td></td>
          <td colspan="2">
            <div class="text-c">
              <table id="fullProTb" class="table table-border table-bordered table-bg radius table-hover">
                <thead>
                  <tr>
                    <th style="width: 9%">商品编号</th>
                    <th style="width: 20%">商品名称</th>
                    <th style="width: 20%">商品分类</th>
                    <th style="width: 20%">供应商</th>
                    <th style="width: 6%">库存</th> 
	  			    <th style="width: 10%">商品原价</th>
                    <th style="width: 10%">商品价格</th>
                    <th style="width: 5%">操作</th>
                  </tr>
                </thead>
                <tbody id="fullProTbody">
                  <#if isUpdate && fullProList??>
                	<#list fullProList as fullPro>
                	  <tr id="${'fullProTr_' + fullPro.product.id}">
                	    <td id="${'fullProTd_id_' + fullPro.product.id}">${fullPro.product.id}</td>
                	    <td>${fullPro.product.baseInfo.name}</td>
                	    <td>
                	      ${fullPro.product.productProperty.prodTypeOne.name}&lt;
		                  ${fullPro.product.productProperty.prodTypeTwo.name}&lt;
		                  ${fullPro.product.productProperty.prodTypeThree.name}
                	    </td>
                	    <td>${fullPro.product.merchant.mercName}</td>
                	    <td>${fullPro.product.storeInfo.storeNum}</td>
                	    <td><#if fullPro.product.priceInfo.payCostMileage?? && fullPro.product.priceInfo.payCostMileage != "">${fullPro.product.priceInfo.payCostMileage + "公里"}</#if></td>
                	    <td>${fullPro.product.priceInfo.payOneMileage}公里</td>
                	    <td>
                	      <a href="javascript:;" style="color: red;" onclick="deleteDomById('${'fullProTr_' + fullPro.product.id}');">删除</a>
                	    </td>
                	  </tr>
                	</#list>
                  </#if>
                </tbody>
              </table>
            </div>
          </td>
        </tr>
        <tr>
          <td>活动简介：</td>
          <td><textarea class="textarea radius" placeholder="请输入活动简介" id="dec" name="dec" maxlength="250">${active.dec}</textarea></td>
          <td>&nbsp;请输入250字以内的活动简介</td>
        </tr>
        <tr>
          <td colspan="2" style="text-align:center;">
            <button type="button" class="btn btn-success radius" onclick="sub_form();">提交</button>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <button type="button" class="btn btn-secondary radius" onclick="closeLayer();">取消</button>
          </td>      
          <td></td>  
        </tr>
      </table>
    </div>
  </form>
</div>
<@frame.end "default"></@frame.end>
<script type="text/javascript" src="${contextPath}/resources/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="${contextPath}/resources/js/presentActivity/activity_add_or_update.js"></script>
<script type="text/javascript">
	var path = "${contextPath}";
	var ruleNum = <#if fullPresentRule??>${fullPresentRule?size}<#else>1</#if>; // 规则数量
	var buyProSize = <#if buyProList??>${buyProList?size}<#else>1</#if>; // 买赠添加商品时需要的行号
</script>